{include file="public/header" /}
<style>
	.layui-upload-list{display: flex;flex-wrap:wrap;}
	.layui-upload-list div{display: inline-block;text-align: center;cursor: pointer;flex-direction: column;display: flex;margin-right: 8px;}
	.layui-upload-list div img{height:100px;}
	.layui-upload-list div video{height:100px;}
	.layui-upload-list div span{display: block;}
	
	#div-slide_show_pic{display:flex;flex-wrap:wrap;}
	.item-img {
		flex-direction: column;
		display: flex;
		margin-right: 18px;
		margin-bottom:17px;width:12%;text-align:center;
	}
	.item-img img{max-width: 100%;}
	.delMultipleImgs4{text-align:center;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加/编辑</h5>
                </div>
                <div class="ibox-content">

					<form id="formEdit" method="post" class="form-horizontal" action="{:url('zhiyuan_goods/edit')}">

	
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">*&nbsp;</span>名称</label>
							<div class="input-group col-sm-4">
								<input type="text" name="title" placeholder="请输入" autocomplete="off" class="form-control"
									   value="{:isset($list.title)?$list.title:''}" >
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">*&nbsp;</span>价格</label>
							<div class="input-group col-sm-4">
								<input type="number" name="price" placeholder="请输入" autocomplete="off" class="form-control"
									   value="{:isset($list.price)?$list.price:''}" >
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">*&nbsp;</span>原价</label>
							<div class="input-group col-sm-4">
								<input type="number" name="price_yj" placeholder="请输入" autocomplete="off" class="form-control"
									   value="{:isset($list.price_yj)?$list.price_yj:''}" >
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">*&nbsp;</span>简述</label>
							<div class="input-group col-sm-4">
								<input type="text" name="short_desc" placeholder="请输入" autocomplete="off" class="form-control"
									   value="{:isset($list.short_desc)?$list.short_desc:''}" >
							</div>
						</div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">轮播图：</label>
                            <div class="input-group col-sm-9">
                                <input type="hidden" class="other_pics" value="{$list['photo']??''}" name="photo" >
								<img src="/static/images/add1.png" class="multiple_upload_img" />
							  
								<span id="div-slide_show_pic">
									{if condition="$list['photo'] neq ''"}
									{volist name="photo" id="vo"}
									<em class="item-img">
									<a target="_bank" href="{$vo}">
									<img src="{$vo}" style="height:80px;"></a>
									<a class="delMultipleImgs4" href="javascript:">删除</a>
									</em>
									{/volist}
									{/if}
								</span>
                            </div>
                        </div>
					 
                        <div class="form-group">
                            <label class="col-sm-3 control-label " for="myEditor">介绍：</label>
                            <div class="input-group col-sm-9">
                                <script src="/static/admin/ueditor/ueditor.config.js" type="text/javascript"></script>
                                <script src="/static/admin/ueditor/ueditor.all.js" type="text/javascript"></script>
                                <textarea name="desc" style="width:90%" id="myEditor">{$list.desc??''}</textarea>
                                <script type="text/javascript">
                                    var editor = new UE.ui.Editor();
                                    editor.render("myEditor");
                                </script>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label " for="myEditor_info">服务详情：</label>
                            <div class="input-group col-sm-9">
                                <textarea name="info" style="width:90%" id="myEditor_info">{$list.info??''}</textarea>
                                <script type="text/javascript">
                                    var editor_info = new UE.ui.Editor();
                                    editor_info.render("myEditor_info");
                                </script>
                            </div>
                        </div>
					
                        <div class="form-group">
                            <label class="col-sm-3 control-label " for="myEditor_questions">常见问题：</label>
                            <div class="input-group col-sm-9">
                                <textarea name="questions" style="width:90%" id="myEditor_questions">{$list.questions??''}</textarea>
                                <script type="text/javascript">
                                    var editor_questions = new UE.ui.Editor();
                                    editor_questions.render("myEditor_questions");
                                </script>
                            </div>
                        </div>
					
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
								<input type="hidden" name="id" value="{:isset($list['id'])?$list['id']:''}">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
					</form>

                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}

<link rel="stylesheet" href="/static/admin/css/layui.css" media="all"/>
<script type="text/javascript" src="/static/admin/js/layui.js"></script>
<script type="text/javascript">
layui.use(['upload'], function () {
	var upload = layui.upload;
    var multiple_images_4 = {$photo_js|html_entity_decode};
	if(multiple_images_4.length == 0){
		multiple_images_4 = [];
	}
	function delMultipleImgs4(this_img){
		//获取下标
		console.log(this_img);
		//var subscript=$("#div-slide_show_pic item-img").index(this_img);
		var subscript=this_img.parent().children().index(this_img);
		console.log($("#div-slide_show item-img"));
		console.log(subscript);
		//删除图片
		this_img.remove();
		console.log(multiple_images_4);
		//删除数组
		multiple_images_4.splice(subscript, 1);
		//重新排序
		//multiple_images_4.sort();
		console.log(multiple_images_4);
		$('.other_pics').val(multiple_images_4);
		//返回
		return ;
	}
	$("body").delegate(".delMultipleImgs4","click",function(){
		//delMultipleImgs4(this);
		//delMultipleImgs4($(this).parent('.item-img').get(0));
		delMultipleImgs4($(this).parent('.item-img'));
	})
	upload.render({
		elem: '.multiple_upload_img',
		url: "{:url('Upload/upload_oss')}",
		accept:'file',
		exts:'jpg|png',
		multiple: true,
		before: function(obj){
		
		},
		done: function(data){
			var icon=5;
			if(multiple_images_4.length>5){
				layer.msg('最多6张图片', {icon:5,time: 1500});
				return false;
			}
			if(!data.code){
				icon=6;
				console.log(multiple_images_4);
				multiple_images_4.push(data.data.src); 
				$('.other_pics').val(multiple_images_4);
				
				$('#div-slide_show_pic').append('<em class="item-img"><img src="'+ data.data.src +'" alt=" " title="" class="layui-upload-img" style="height:80px;"><a class="delMultipleImgs4" href="javascript:">删除</a></em>&nbsp;')
			}
			layer.msg(data.msg, {icon:icon,time: 1500});
		},
		error: function(){
			layer.msg('上传失败', {icon:5,time: 1500});
		}
	});
});

    //提交
    $(function(){
        $('#formEdit').ajaxForm({
            beforeSubmit: checkForm, 
            success: complete, 
            dataType: 'json'
        });
        

		
        function checkForm(){
            if( '' == $.trim($('input[name="title"]').val())){
                layer.msg('请输入名称',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
			var valid_type = $.trim($('input[name="valid_type"]:checked').val());
			//alert(valid_type);
            if('' == $.trim($('input[name="price"]').val())){
                layer.msg('请输入价格',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
        }


        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('ZhiyuanGoods/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;   
            }
        }
     
    });

</script>
</body>
</html>